#pragma once
#include "Misc.h"
#include "IGeometry.h"
namespace RayTrace{

	class CTriangle:public IGeometry
	{
	public:
		class IntSectInf
		{
		public:
			//vector3 pos;
			vector3 barycentric;
		};
	public:
		CTriangle(const vector3& p1,const vector3& p2,const vector3& p3);
		~CTriangle(void);


//		double InterSectionWithRay(const Ray& inRay,IntSectInf& inf);
		bool InArea(const vector3& point);
		bool InArea(const vector3& point,IntSectInf& inf);
		double DistRayThroughPlane(const Ray& ray);
		bool IsThroughByRay(const Ray&ray,double t);
		const vector3& GetNormal();
		const vector3& operator[](int n)const ;
	protected:
		bool GetBaryCentricCoordinate(const vector3& vi, const vector3& v1,const vector3& v2,const vector3& v3,vector3& barycentric );
	protected:
		vector3 v1,v2,v3;
		vector3 normal;//normal must be recalculate when vertex has changed.
	};
}